/*
 * TypingStructure.h
 * VB Script Analyzer
 * @author Gregoire JACOB (gregoire.jacob@orange-ftgroup.com)
 * @date 25/01/2008
 * @version 1.0
 */

//Object types
#define TYPE_VAR	1
#define TYPE_PERM	2
#define TYPE_COM	3
#define TYPE_BOOT	4
#define TYPE_THIS	5
static char typestr[6][15] = {"unknown","var","objperm","objcom","objboot","this"};
//Object natures
#define OBJ_FILE	1
#define OBJ_FOLD	2
#define	OBJ_DRIVE	3
#define OBJ_REG		4
#define OBJ_NETW	5
#define OBJ_MAIL	6
#define VAR			7
static char naturestr[8][15] = {"none","file","folder","drive",
								"registry key","network","mail","variable"}; 
//Object status
#define OBJ_EXIST	1
#define OBJ_CREATED	0


#define MAXNBREFALIAS 15
//Object type
struct TYPED_OBJ{
	char	ObjectName[NAME_MAX_LENGTH];
	int		nbalias;
	int		nbref;
	char *	ObjectAliases[MAXNBREFALIAS];
	char *	ObjectReferences[MAXNBREFALIAS];
	int		Type;
	int		Nature;
	int		Status;		
};

//Global typing structure
struct TYPING{
	int		nbobj;
	struct	TYPED_OBJ objects[800];
};



/**
 * printStructures()
 * @param the structure to render
 * Print the different information of a given structure in the console
 */
void printTypedObject(struct TYPED_OBJ * object, int number);
void printfTypedObject(FILE * f, struct TYPED_OBJ * object, int number);
void printTyping(struct TYPING * types);
void printfTyping(FILE * f, struct TYPING * types);

/**
 * storeStructures()
 * @param the structure to render
 * @param the file storing the object database
 * Store in a database the different information in a binary mode
 */
void storeTypedObject(FILE * db, struct TYPED_OBJ * object);
void storeTyping(FILE * db, struct TYPING * types);

/**
 * isKnownObject()
 * @param the current typing structure
 * @param the current token
 * @return the index of the object if present in the table, otherwise -1
 * Test if the given token is already in the table as name, alias or reference
 */
int isKnownObject(struct TYPING * types, char *  token);

/**
 * addNewObject()
 * @param the current typing structure
 * @param the object name (may be null)
 * @param the object nature
 * @return the index of the created object
 * @warning the object type is determined by a call to the classifier
 */
int addNewObject(struct TYPING * types, char * name, int nature);

//Access and updates methods
int getObjectType(struct TYPING * types, int obj);
int getObjectNature(struct TYPING * types, int obj);
void setObjectType(struct TYPING * types, int obj, int type);
void setObjectNature(struct TYPING * types, int obj, int nature);
void setObjectStatus(struct TYPING * types, int obj, int status);
void addObjectReference(struct TYPING * types, int obj, char * reference);
void addObjectAlias(struct TYPING * types, int obj, char * alias);
void removeObjectReference(struct TYPING * types, int obj, char * reference);
void updateObjectType(struct TYPING * types, int obj);

/**
 * updateTypesAfterSysCall()
 * @param the current typing structure
 * @param the system call parameter
 * @param the system call returned value
 * @param the system call nature
 * @param flag indicating that the object is overwrite
 * @return the index of the modified/created object
 */
int updateTypesAfterSysCall(struct TYPING * types, char * param, 
							char * ret, int nature, int status);

/**
 * updateTypesBeforeLocCall()
 * @param the current typing structure
 * @param the system call parameter
 * @param the system call returned value
 * @param the system call nature
 * @return the index of the modified/created object
 */
int updateTypesBeforeLocCall(struct TYPING * types, char * param, char * arg);

/**
 * updateReturnStorage()
 * @param the current typing structure
 * @param the function name storing the function result
 * @param the returned value
 * @return the index of the modified/created object
 */
int updateReturnStorage(struct TYPING * types, char * function, char * value);
